package com.zrgj.config;

import com.zrgj.quartz.SMS;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//@Configuration
public class QuartzConfig {
    @Bean
    public JobDetail getJobDetail() {
        return JobBuilder.newJob(SMS.class).withIdentity("smsJob").storeDurably().build();
    }

    @Bean
    public CronTrigger getCronTrigger(){
        //1.获取CronScheduleBuilder对象
        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("0/2 * * * * ?").withMisfireHandlingInstructionDoNothing();

        //2.获取CronTrigger对象
        CronTrigger cronTrigger = TriggerBuilder.newTrigger().forJob(getJobDetail())
                .withIdentity("cronTrigger").withDescription("这是cron触发器").startNow()
                .withSchedule(cronScheduleBuilder).build();

        return cronTrigger;
    }

}
